class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        //定义一个虚拟结点
        ListNode newHead = new ListNode(0);
        ListNode tmp = newHead;

        ListNode cur1 = l1, cur2 = l2;
        //定义一个变量存储进制
        int t = 0;
        //判断条件
        while (cur1 != null || cur2 != null || t != 0) {
            if (cur1 != null) {
                t += cur1.val;
                cur1 = cur1.next;
            }
            if (cur2 != null) {
                t += cur2.val;
                cur2 = cur2.next;
            }
            //t有可能会超过10 取个位数
            ListNode ret = new ListNode(t % 10);
            tmp.next = ret;
            tmp = tmp.next;
            //t要进一步处理
            t /= 10;
        }
        return newHead.next;
    }
}

public class Test01 {

}
